
import Vue from 'vue'
import VueRouter from 'vue-router'

// 0 模块化编程
Vue.use(VueRouter)   // 全局注册声明 

// 1. 定义路由组件
// @ is alias src 
import Home from '@/views/Home.vue'
import Find from '@/views/Find.vue'

// 2. 定义路由配置选项
const routes = [
    {
        path:"/",
        redirect:{name:"home"}
    },
    {
        path:'/home',
        name:'home',
        component:Home,
    },
    {
        path:"/find",
        name:'find',
        component:Find 
    },
    // 路由懒加载 只有当前路由激活的时候才去引入路由组件  性能优化
    {
        path:"/mine",
        name:"mine",
        component:()=>import('@/views/Mine.vue')
    },
    {
        path:"/404",
        name:"notfound",
        component:()=>import('@/views/404.vue')
    },
    {
        path:"*",
        redirect:"/404"
    }
]
// 3. 创建路由对象 
const router = new VueRouter({
    mode:"history",
    routes,
})

// 4. 挂载到根实例 
export default router